<template>
	<view>
		<cu-custom bgColor="theme-bg-color" :isBack="true">
			<block slot="content">组 织 列 表 </block>
		</cu-custom>
		<view class="cu-bar theme-bg-color search">
			<view class="search-form radius">
				<text class="cuIcon-search"></text>
				<input v-model.trim="keyword" :adjust-position="false" type="text" placeholder="搜索您的班级~~"
					confirm-type="search" @confirm="Search()"></input>
			</view>
			<view class="action" @click="Search()">
				<text class="cuIcon-search"></text>
				<text>搜索</text>
			</view>

		</view>

		<view class='bg-white margin-xs'>
			<view v-if="OrganizationList.length>0" v-for="(item,index) in OrganizationList">
				<view class="flex dashed-bottom padding-bottom-lg padding-top-xs" @click='Apply(item)'>
					<image style="width:180upx;height:180upx;border-radius: 10upx;" mode="aspectFill" :src="item.Cover">
					</image>
					<view class="padding-left-xs">
						<view class="text-lg text-bold margin-bottom-xs ">{{item.Name}}</view>
						<view class="text-xs margin-bottom-xs">{{item.LinkName}}</view>
						<view class="text-xs margin-bottom-xs">{{item.Phone}}</view>
						<view class="text-xs margin-bottom-xs">{{item.Address}}</view>
					</view>
				</view>

			</view>
			<view v-else>
				<cu-no-data></cu-no-data>
			</view>
		</view>
		<view style="height:120upx"></view>
		<view class="fixed-bottom">
			<button class="cu-btn block theme-bg-color margin-tb-sm lg" @click="MyApplyRecord()">我的申请记录</button>

		</view>
	</view>
</template>

<script>
	import store from "@/store";
	import {
		mapGetters
	} from "vuex";
	export default {
		data() {
			return {
				keyword: "",
				Where: {},
				OrganizationList: []
			}
		},
		computed: {
			...mapGetters([
				'token', 'RoleTypeFormat', "userInfo", "userId"
			])
		},
		onLoad(option) {
			this.OrganizationListApi();
		},
		onShow() {

		},
		methods: {
			/**
			 * 班级查询
			 */
			async OrganizationListApi() {
				let {
					Data: {
						Items
					}
				} = await this.$http.PostAsync("/Organization/List", {
					...this.Where
				});
				this.OrganizationList = Items;
			},
			async Search() {
				this.Where.Name = this.keyword;
				this.OrganizationListApi();
			},
			//申请班级
			async Apply(item) {

				let confirm = await this.$comm.ShowModal("你确定要申请该班级吗?");
				if (confirm == false) {
					await this.$comm.ShowToast("用户放弃操作");
					return;
				}
				uni.navigateTo({
					url: "/pages/Organization/OrganizationApply?OrganizationId=" + item.Id
				})


			},
			async MyApplyRecord(){
				uni.navigateTo({
					url: "/pages/Organization/OrganizationApplyRecord" 
				})
			}
		}
	}
</script>

<style>

</style>